<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #app {
            width: 40vw;
            border: 1px solid #ccc;
            margin: 10vh auto;
            padding: 10px;
        }

        #app .title {
            text-align: center;
        }

        li {
            list-style-type: none;
            margin-left: -20px;
            margin-top: 25px;
            width: 100%;
            font-size: 18px;
            border-bottom: 1px solid #ccc;
        }

        li span {
            display: inline-block;
            width: 87%;
        }

        button {
            color:black;
            font-weight: bolder;
            width: 40px;
            height: 40px;
            border-radius: 30%;
        }
        
        .add{
            font-size: 26px;
        }
        input[type='text'] {
            width: 80%;
            height: 40px;
            font-size: 18px;
            border-radius: 5px;
            padding-left: 3px;
            margin-left: 20px;

        }
        .tips{
            text-align: center;
            font-size:16px;
            color:rgba(39, 36, 31, 0.534)
        }
    </style>
</head>

<body>
    <div id="app">
        <h2 class="title">飞飞记事本</h2>
        <input type="text" placeholder="请输入非空内容，点击加号记录" v-model.trim="todo" @keyup.enter="addTodo">
        <button @click="addTodo" class="add">+</button>
        <ul>
            <li v-for="(item,index) in todoList" :key="index" @dblclick="remove(index)"><span >{{index+1}}.{{item}}</span><button
                    class="cancel" @click="remove(index)">X</button></li>
        </ul>
        <div class="tips">双击删除对应项</div>
    </div>
</body>
<script src="./js/vue.js"></script>
<script>
    new Vue({
        el: "#app",
        data: {
            todo: " ",
            todoList: ['抽烟', '喝酒', '烫头', 'eat', 'sleep', 'play Doug']
        },
        methods: {
            addTodo() {
                if (!this.todo) {
                    alert('请输入非空信息')
                }
                else {

                    this.todoList.unshift(this.todo)
                    this.todo = " "
                }
            },
            remove(index){
             this.todoList.splice(index,1)
                
            }
        }
    })
</script>

</html>